let zhEl = document.querySelector('.zh');
let emialEl = document.querySelector('.emial');
let mmEL = document.querySelector('.mm');
let qmEl = document.querySelector('.qm');
let loginEl = document.querySelector('.login')

// 绑定点击事件
loginEl.onclick = async function () {
  //获取数据

  let username = zhEl.value.trim()
  let tel = mmEL.value.trim()
  let password = qmEl.value.trim()
  let emial = emialEl.value.trim()
  //数据校验
  if (!username || !tel) {
    return alert('用户名，密码未填写')
  }
  if (tel != password) {
    return alert('密码不一致')
  }
  //发送到服务端
  let res = await axios({
    method: 'POST',
    url: ' http://localhost:8000/api/user/register', // 每个接口的地址都不一样
    data: {
      username,
      tel,
      password,

    },
  })
  console.log(res);
  // 根据返回内容作出对应响应（失败->提示，成功->跳转至登陆）
  let { code, msg } = res.data

  // 报错，弹出错误信息
  if (code) {
    return alert(msg)
  }
  // 注册成功，跳转至登陆
  location.href = './btn_logn.html'


}
